<template>
<div class="abilityAddcon" v-if="addVisible">
    <div>
        <div class="twoStageWindow">
            <div class="twoStageWindowTitle">
                {{newOrEdit=='new'?'新增能力参数':(newOrEdit=='edit'?'编辑能力参数':(newOrEdit=='look' || newOrEdit=='review'?'查看能力参数':(newOrEdit=='copy'?'复制能力参数':"生成新版本")))}}
                <div class="twoStageWindowClose" v-if="newOrEdit != 'review'">
                    <el-button size="mini" type="primary" v-if="isNewViserion && $parent.userOpernation.version.display" @click="changeStatus()">生成新版本</el-button>
                    <el-button size="mini" type="primary" v-on:click="submitAbility('commit')" v-if="isSubmit" :disabled="!isRepeat">提交</el-button>
                    <el-button size="mini" type="primary" @click="submitAbility('save')" v-if="isSave" :disabled="!isRepeat">保存</el-button>
                    <el-button size="mini" v-on:click="close('abilityForm')">取消</el-button>
                </div>
                <div class="twoStageWindowClose" v-if="newOrEdit == 'review'">
                    <el-button type="primary" @click="reviewFlowPop" size="mini">审核</el-button>
                    <el-button size="mini" v-on:click="close('abilityForm')">取消</el-button>
                </div>
            </div>

            <div class="containercontent" style="margin-top:40px;height:calc(100% - 40px);padding-top: 0;">
                <div class="form">
                    <el-form style="height:100%;" label-width="110px" :inline="false" class="demo-form-inline abilityForm" :model="abilityForm" :rules="abilityRules" ref="abilityForm">
                        <el-form-item label="名称" prop='name'>
                            <el-col :span="22">
                                <el-input size="mini" v-model="abilityForm.name" :title="abilityForm.name" placeholder="请输入内容" :disabled="!isDisabled"></el-input>

                            </el-col>
                        </el-form-item>
                        <el-form-item label="版本" prop='version' v-if="newOrEdit != 'new' && newOrEdit != 'copy' && newOrEdit != 'newVersion'">
                            <el-col :span="22">
                                <el-input size="mini" v-model="abilityForm.version" placeholder="请输入内容" disabled></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="检测对象" prop="detectObject">
                            <el-col :span="22">
                                <el-select v-model="abilityForm.detectObject" placeholder="请选择" size="mini" :disabled="!isDisabled" filterable>
                                    <el-option v-for="item in objectSelect.itemList" :key="item.code" :label="item.name" :value="item.code">
                                    </el-option>
                                </el-select>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="CNAS" prop="cnasStatus" v-if="newOrEdit != 'new' && newOrEdit != 'copy' && newOrEdit != 'newVersion'">
                            <el-col :span="22">
                                <el-checkbox v-model="abilityForm.cnasStatus" :true-label=1  :false-label=0  @change="changeHas($event,'cnasStatus')" :disabled="newOrEdit == 'look'"></el-checkbox>
                            </el-col>
                        </el-form-item>


                        <el-form-item label="检测方法" prop="method" class="methodsVail method">
                            <el-col :span="22">
                                <el-cascader :options="MethodAndType" v-model="outMethod" :title="outMethodName" size="mini" style="width:100%;" @change="changeMethod" :disabled="!isSubmit">
                                </el-cascader>
                            </el-col>
                            <div class="el-form-item__error" v-if="methodError">
                                请选择检测方法
                            </div>
                        </el-form-item>
                        <el-form-item label="主仪器类别" prop="mainEquiptype" class="methodsVail equipVail" v-if = "false">
                            <el-col :span="22">
                                <el-cascader :options="mainEquipmentType" v-model="outMainEquipment" :title="outMainEquipmentName" size="mini" style="width:100%;" :disabled="!isSubmit" @change="changeEquipMent">
                                </el-cascader>
                            </el-col>
                            <div class="el-form-item__error" v-if="equipError">
                                请选择仪器类别
                            </div>
                        </el-form-item>
                        <el-form-item label="分组" prop="group">
                            <el-col :span="22">
                                <el-select v-model="abilityForm.group" placeholder="由方法带出，分组仅做展示，不允许修改" size="mini" disabled>
                                    <el-option v-for="item in groupSelect.itemList" :key="item.code" :label="item.name" :value="item.code">
                                    </el-option>
                                </el-select>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="使用校准曲线" prop="doUseCurve">
                            <el-col :span="22">
                                <el-select v-model="abilityForm.doUseCurve" size="mini" :disabled="!isSubmit" @change="changeLine">
                                    <el-option v-for="item in yesorno" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                                <!--<el-switch  v-model="abilityForm.doUseCurve" active-text="是"  inactive-text="否" ></el-switch>-->
                            </el-col>
                        </el-form-item>

                        <el-form-item label="CMA" prop="cmaStatus" v-if="newOrEdit != 'new' && newOrEdit != 'copy' && newOrEdit != 'newVersion'">
                            <el-col :span="22">
                                <el-checkbox v-model="abilityForm.cmaStatus" :true-label=1  :false-label=0 @change="changeHas($event,'cmaStatus')" :disabled="newOrEdit == 'look'"></el-checkbox>
                            </el-col>
                        </el-form-item>
                        <!--<el-form-item label="编码" prop="code" v-if="newOrEdit != 'new' && newOrEdit != 'copy' && newOrEdit != 'newVersion'">
                            <el-col :span="22">
                                <el-input size="mini" placeholder="系统自动生成" v-model="abilityForm.code" disabled></el-input>
                            </el-col>
                        </el-form-item>

                        <el-form-item label="状态" prop="status" v-if="newOrEdit != 'new' && newOrEdit != 'copy' && newOrEdit != 'newVersion'">
                            <el-col :span="22">
                                <el-select v-model="abilityForm.status" size="mini" disabled>
                                    <el-option v-for="item in enableStatus" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-col>
                        </el-form-item>-->

                    </el-form>
                </div>
                <div class="elTab">
                    <el-tabs v-model="activeTab">
                        <el-tab-pane label="检测项目" name="first">
                            <div style="float:right;margin-bottom:5px;">
                                <el-button type="primary" size="mini" @click="submitItem" v-if="$parent.userOpernation.openUpdate.display && isStatus == 1 && newOrEdit == 'edit'">保存</el-button>
                            </div>
                            <el-table :data="itemBeanList" style="width: 100%;height:calc(100% - 35px);" size="mini" class="tableCon">
                                <el-table-column label="序号" fixed min-width="50px">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="选择" fixed min-width="170px" property="status">
                                    <template slot-scope="scope">
                                        <el-switch v-model="scope.row.status" :disabled="!isDisabled2" active-text="启用" inactive-text="停用" :active-value="1" :inactive-value="0" @change="changeItem($event,scope.row,'item')">
                                        </el-switch>
                                    </template>
                                </el-table-column>
                                <el-table-column property="itemName" label="检测项目" fixed min-width="150px" show-overflow-tooltip>

                                </el-table-column>
                                <el-table-column property="dataType" label="数据类型" min-width="120px">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.dataType" size="mini" disabled>
                                            <el-option v-for="item in dataSelect.itemList" :key="item.code" :label="item.name" :value="item.code">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column property="high" label="测定上限" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-input v-model="scope.row.high" size="mini" placeholder="请输入内容" :disabled="!isDisabled2" class="deal" oninput="this.value=this.value.replace(/[^0-9.]+/,'');"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column property="low" label="测定下限" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-input  v-model="scope.row.low" size="mini" placeholder="请输入内容" :disabled="!isDisabled2" class="deal" oninput="this.value=this.value.replace(/[^0-9.]+/,'');"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column property="detectionLimit" label="方法检出限" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-input v-model="scope.row.detectionLimit" size="mini" placeholder="请输入内容" :disabled="!isDisabled2" class="deal" oninput="this.value=this.value.replace(/[^0-9.]+/,'');"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column property="unitName" label="单位" min-width="150px" :show-overflow-tooltip="true">
                                </el-table-column>
                                <el-table-column property="formulaAlias" label="公式" min-width="150px" :show-overflow-tooltip='true'>
                                </el-table-column>
                                <el-table-column property="decimalRule" label="修约规则" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.decimalRule" size="mini" disabled>
                                            <el-option v-for="item in ruleSelect.itemList" :key="item.code" :label="item.name" :value="item.code">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column property="decimalNumber" label="小数点后位数" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-input  v-model="scope.row.decimalNumber" placeholder = "小数点后保留位数" :disabled="!isDisabled2"  class = "deal" size="mini" @blur="decNumber(scope.row)" oninput="this.value=this.value.replace(/[^0-9]+/,'');" ></el-input>
                                    </template>
                                </el-table-column>
                            </el-table>

                        </el-tab-pane>
                        <el-tab-pane label="分析项" name="second">
                            <div style="float:right;margin-bottom:5px;">
                                <el-button type="primary" size="mini" @click="submitAnalysis" v-if="$parent.userOpernation.openUpdate.display && isStatus == 1 && newOrEdit == 'edit'">保存</el-button>
                            </div>
                            <el-table :data="analysisBeanList" style="width: 100%;height:100%;" size="mini" class="tableCon">
                                <el-table-column label="序号" fixed min-width="50px">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="选择" fixed min-width="170px" property="status">
                                    <template slot-scope="scope">
                                        <el-switch v-model="scope.row.status" :disabled="!isDisabled2" active-text="启用" inactive-text="停用" :active-value="1" :inactive-value="0" @change="changeItem($event,scope.row,'anasy')">
                                        </el-switch>
                                    </template>
                                </el-table-column>
                                <!--:disabled="!scope.row.canedit"-->
                                <el-table-column property="name" label="名称" fixed min-width="150px" show-overflow-tooltip>
                                    <!--<template slot-scope="scope">

<el-input v-model="scope.row.name" size="mini" placeholder="请输入内容" disabled></el-input>

</template>-->
                                </el-table-column>
                                <el-table-column property="type" label="类型" min-width="130px">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.type" size="mini" disabled>
                                            <el-option v-for="item in typeSelect" :key="item.code" :label="item.name" :value="item.code">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <!-- fenxixiangleixing -->
                                <el-table-column property="dataType" label="数据类型" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.dataType" size="mini" disabled>
                                            <el-option v-for="item in dataSelect.itemList" :key="item.code" :label="item.name" :value="item.code" disabled>
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>

                                <el-table-column property="decimalRule" label="修约规则" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.decimalRule" size="mini" disabled>
                                            <el-option v-for="item in ruleSelect.itemList" :key="item.code" :label="item.name" :value="item.code">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column property="decimalNumber" label="小数点后位数" min-width="100px">
                                    <!--<template slot-scope="scope">

<el-input-number v-model="scope.row.decimalNumber" size="mini" :min="0" disabled></el-input-number>

</template>-->
                                </el-table-column>
                                <el-table-column label="默认值" property="defaultValue">
                                    <template slot-scope="scope">
                                        <el-input size="mini" v-model="scope.row.defaultValue" :disabled="!isDisabled2"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column property="formulaAlias" label="公式" min-width="180px" :show-overflow-tooltip='true'>
                                </el-table-column>
                                <el-table-column property="unitName" label="单位" min-width="100px" :show-overflow-tooltip='true'>
                                </el-table-column>
                            </el-table>

                        </el-tab-pane>
                        <el-tab-pane label="质控计划" name="five" v-if="newOrEdit != 'new' && newOrEdit != 'copy'&& newOrEdit != 'newVersion'">
                            <div class="selectw100" style="height:40px;" v-if="isDisabled2">
                                <div class="basicRightDistanceA" style="position:absolute;top: 0px;">
                                    <el-button type="primary" size="mini" @click="addQcPlanShow" >添加质控计划</el-button>
                                </div>
                            </div>
                            <el-table :data="qcDetecList" style="width: 100%;height:100%;" size="mini" class="tableCon">
                                <el-table-column label="序号" min-width="100px">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>
                                <el-table-column property="qcName" label="名称" min-width="100px">
                                </el-table-column>
                                <el-table-column property="typeName" label="类型" min-width="100px">
                                </el-table-column>
                                <el-table-column property="isDo" label="是否必做" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-checkbox v-model="scope.row.isDo"  @change="(value) => changeIsDo(value, scope.row)" :disabled="!isDisabled2 || (scope.row.source != undefined && scope.row.source != '' && scope.row.source != null)"></el-checkbox>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作" min-width="100px" v-if="isDisabled2">
                                    <template slot-scope="scope">
                                        <el-button type="text" size="mini" @click="deleteQcPlan(scope.row)" :disabled = "(scope.row.source != undefined && scope.row.source != null && scope.row.source != '') && scope.row.isDo">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="采样要求" name="third">
                            <div style="float:right;margin-bottom:5px;">
                                <el-button type="primary" size="mini" @click="updateDetectabilityBean('clickSave')" v-if="$parent.userOpernation.openUpdate.display && isStatus == 1 && newOrEdit == 'edit'">保存</el-button>
                            </div>
                            <el-table :data="abilityForm.bottle" style="width: 100%;height:100%;" class="tableCon" size="mini">
                                <el-table-column label="序号" min-width="100px">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>

                                <el-table-column property="bottleType" label="容器类型" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.bottleType" size="mini" :disabled="!isDisabled2">
                                            <el-option v-for="item in bottleOptions" :key="item.id" :label="item.name" :value="item.id">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column property="capacity" label="采样体积(mL)" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-input-number v-model="scope.row.capacity" size="mini" :min="0" :step="50" :disabled="!isDisabled2"></el-input-number>
                                    </template>
                                </el-table-column>
                                <el-table-column property="doAlone" label="单独采样" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.doAlone" size="mini" :disabled="!isDisabled2">
                                            <el-option v-for="item in yesorno" :key="item.value" :label="item.label" :value="item.value">
                                            </el-option>
                                        </el-select>
                                        <!--<el-input-number v-model="scope.row.doAlone" size="mini" :min="0" :step="50"></el-input-number>-->
                                    </template>
                                </el-table-column>
                                <el-table-column property="media" label="保存剂" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-input v-model="scope.row.media" size="mini" :disabled="!isDisabled2"></el-input>
                                    </template>
                                </el-table-column>
                                 <el-table-column property="saveTime" label="保存时间(h)" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-input v-model="scope.row.saveTime" size="mini" class="deal" oninput="this.value=this.value.replace(/[^0-9]+/,'');" :disabled="!isDisabled2"></el-input>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="默认检测人" name="six" v-if="newOrEdit != 'new' && newOrEdit != 'copy'&& newOrEdit != 'newVersion'">
                            <el-table :data="abilityForm.defaultAnalysts" style="width: 100%" size="mini">
                                <el-table-column label="序号" min-width="100px">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>
                                <el-table-column property="defaultAnalysts" label="检测员">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.defaultAnalysts" size="mini" filterable remote :remote-method="readUser" clearable @focus='validAnalysts' @change="addAnalysts" :disabled="!isDisabled2" >
                                            <el-option v-for="item in userData" :key="item.account" :label="item.name" :value="item.account">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="主仪器" name="four" v-if="newOrEdit != 'new' && newOrEdit != 'copy'&& newOrEdit != 'newVersion'">
                            <div class="selectw100" style="height:40px;float:right" v-if="isDisabled2">
                                <el-button type="primary" size="mini" @click="addyiqiShow('main')" v-if="mainEquipmentBeanList.length == 0">添加仪器</el-button>
                                <el-button type="primary" size="mini" @click="addyiqiShow('main')" v-if="mainEquipmentBeanList.length != 0">修改仪器</el-button>

                            </div>
                            <el-table :data="mainEquipmentBeanList" style="width: 100%;height:calc(100% - 35px)" size="mini" class="tableCon" v-if="reload" >
                                <el-table-column label="序号" width="70px">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>
                                <el-table-column property="name" label="名称" min-width="100px" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column property="equipmentTypeName" label="类型" min-width="100px" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column property="officesName" :label="stationName" min-width="100px" show-overflow-tooltip>
                                  <template slot-scope="scope">
                                    {{scope.row.offices == 'ALL'?"全部":(scope.row.officesName?scope.row.officesName:"---")}}
                                  </template>
                                </el-table-column>
                                <el-table-column property="isDefault" label="是否默认" min-width="100px">
                                    <template slot-scope="scope">
                                        <el-checkbox v-model="scope.row.isDefault"  @change = "(val) => changeisDefault(scope.row,val)"  :disabled = "!isDisabled2"></el-checkbox>
                                        <!--<el-select v-model="scope.row.isDefault" size="mini" @change = "(val) => changeisDefault(scope.row,val)">
                                            <el-option v-for="item in yesorno" :key="item.value" :label="item.label" :value="item.value">
                                            </el-option>
                                        </el-select>-->
                                    </template>
                                </el-table-column>
                                <el-table-column  label="操作" min-width="100px"  v-if="isDisabled2">
                                    <template slot-scope="scope">
                                        <el-button @click="deleteEquip(scope.row)" type="text" size="mini" v-if="newOrEdit != 'new' && newOrEdit != 'copy'&& newOrEdit != 'newVersion'" >删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="辅仪器" name="ten" v-if="newOrEdit != 'new' && newOrEdit != 'copy'&& newOrEdit != 'newVersion'">

                            <div class="selectw100" style="height:40px;float:right" v-if="isDisabled2">
                                <el-button type="primary" size="mini" @click="addyiqiShow('assiment')" v-if="equipmentBeanList.length == 0">添加仪器</el-button>
                                <el-button type="primary" size="mini" @click="addyiqiShow('assiment')" v-if="equipmentBeanList.length != 0">修改仪器</el-button>
                            </div>
                            <el-table :data="equipmentBeanList" style="width: 100%;height:calc(100% - 35px)" class = "tableCon" size="mini" v-if="reload">
                                <el-table-column label="序号" width="70px">
                                    <template slot-scope="scope">
                                        {{scope.$index+1}}
                                    </template>
                                </el-table-column>
                                <el-table-column property="name" label="名称" min-width="120px" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column property="equipmentTypeName" label="类型" min-width="100px" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column property="officesName" :label="stationName" min-width="100px" show-overflow-tooltip>
                                  <template slot-scope="scope">
                                    {{scope.row.offices == 'ALL'?"全部":(scope.row.officesName?scope.row.officesName:"---")}}
                                  </template>
                                </el-table-column>
                                <el-table-column property="isDefault" label="是否默认" min-width="80px">
                                    <template slot-scope="scope">
                                        <el-checkbox v-model="scope.row.isDefault"  @change = "(val) => changeisDefault(scope.row,val)" :disabled = "!isDisabled2"></el-checkbox>
                                        <!--<el-select v-model="scope.row.isDefault" size="mini" @change = "(val) => changeisDefault(scope.row,val)">
                                            <el-option v-for="item in yesorno" :key="item.value" :label="item.label" :value="item.value">
                                            </el-option>
                                        </el-select>-->
                                    </template>
                                </el-table-column>
                                 <el-table-column  label="操作" min-width="100px"  v-if="isDisabled2">
                                    <template slot-scope="scope">
                                        <el-button @click="deleteEquip(scope.row)" type="text" size="mini" v-if="newOrEdit != 'new' && newOrEdit != 'copy'&& newOrEdit != 'newVersion'" >删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-tab-pane>

                        <el-tab-pane label="审核信息" name="hhh" v-if="(newOrEdit == 'look') && isStatus != 2 && (abilityForm.source == '' || abilityForm.source == null || abilityForm.source == undefined ) ">
                            <div id="myIframe" v-loading="loading1" style = "text-align:center">
                                <span style = "color:#909399;line-height:100px;" v-if = "WorkFlowMsg != '' && WorkFlowMsg != undefined" >{{WorkFlowMsg}}</span>
                                <iframe :src="url" id="workFlowIframe" ref="workFlowIframe" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>
                            </div>
                        </el-tab-pane>

                    </el-tabs>
                </div>

            </div>
            <div class="user-footer" v-if="newOrEdit == 'look'">
                <span>
                创建人:{{abilityForm.createBy}}
              </span>
                <span>
                创建时间:{{abilityForm.createTime}}
              </span>
                <span v-if="abilityForm.updateBy != undefined">
                修改人：{{abilityForm.updateBy}}
              </span>
                <span v-if="abilityForm.updateTime != undefined">
                修改时间：{{abilityForm.updateTime}}
              </span>
            </div>
        </div>
    </div>
    <addyiqi :addVisible.sync="addyiqishow" :detectAbiltyId="detectAbiltyId" :mainEquiptype="abilityForm.mainEquiptype" :isMain="newOrEditEquip" @getablityequipment="getAblityEquipment"></addyiqi>
    <!--:detectAbiltyId="detectAbiltyId"-->
    <add-qc-plan :addVisible.sync="addQcshow" :newOrEditQcPlan="newOrEditQcPlan" :detectAbiltyId="detectAbiltyId"></add-qc-plan>
    <review-flow :addVisible.sync="reviewFlowShow" :reviewData="reviewData" :procInstType="procInstType" :reviewTitle="reviewTitle" @reloadMain="readAbility"></review-flow>
</div>
</template>

<script>
import {
    mapState
} from 'vuex'
import $ from 'jquery'
const addyiqi = () =>
    import('./addyiqi.vue');
const addQcPlan = () =>
    import('./addqcplan.vue');
const reviewFlow = () =>
    import('../../../../common/reviewFlow.vue');

export default {
    data() {
        const that = this;
        return {
            groupValue: '',
            outMethod: [],
            outMethodName: null,
            abilityForm: {
                name: '',
                detectObject: '',
                doUseCurve: true,
                mainEquiptype: '',
                status: 2,
                method: '',
                methodBean: {
                    analysisBeanList: [],
                    itemBeanList: [],
                },
                bottle: [{}], //容器
                defaultAnalysts: [{}], //默认检测人列表
                version: '',
                cnasStatus:0,
                cmaStatus:0,


                // doDefaultMethod: null,
            },
            activeTab: 'first',

            analysisBeanList: [], //分析项
            itemBeanList: [], //检测项目
            equipmentBeanList: [], //辅助仪器列表
            mainEquipmentBeanList: [], //仪器里面主仪器列表
            qcDetecList: [], // 质控计划列表
            reload: true, // 是否重新加载
            newOrEditEquip: "main", //是主仪器还是辅助仪器
            newOrEditQcPlan: 'new', //新增还是修改质控计划
            methodId: null, // 选中的方法

            abilityRules: {
                name: [{
                    required: true,
                    message: '请填写名称',
                    trigger: 'blur'
                }, ],
                detectObject: [{
                    required: true,
                    message: '请选择检测对象',
                    trigger: 'change'
                }, ],
                doUseCurve: [{
                    required: true,
                    message: '请选择是否使用校准曲线',
                    trigger: 'change'
                }],
                // doDefaultMethod: [{
                // 	required: true,
                // 	message: '请选择是否默认方法',
                // 	trigger: 'change'
                // }]

            },
            oldVersion: '',
            detectAbiltyId: null, //当前编辑的能力参数id
            allItem: [], //所有的检测项目

            MethodAndType: [], //检测方法值
            mainEquipmentType: [], //主仪器
            outMainEquipment: [],
            outMainEquipmentName: [],
            isStatus: 0,
            methodCode: '', //选中的方法的code
            mainEquiptypeCode: '', //选中的仪器的code
            methodError: false, //验证检测方法的错误信息
            equipError: false, //仪器错误信息
            allUnit: [], //存放所有单位
            loading: false,
            userData: [], //存放所有的人员
            defaultAnalystsName: '', //默认检测人的姓名
            addyiqishow: false, //添加仪器弹框
            addQcshow: false, //添加QC弹框
            sisForm: {
                name: ""
            },
            sisFormRules: {
                name: [{
                    required: true,
                    message: '请填写名称',
                    trigger: 'blur'
                }],
            },
            addNameShow: false,
            reviewFlowShow: false, //审核流显示
            reviewData: null, //点击行需要审核的信息
            procInstType: 't_detectability', //审核流要查的表
            reviewTitle: '能力参数',
            // fromData:{},
            isSave: false, //保存按钮显示和隐藏,新增和生成新版本，状态为草稿时出现
            isSubmit: true, //提交按钮 只有查看时不出现
            isDisabled: true, //主题是否可编辑状态
            isNewViserion: false, //新版本按钮
            isDisabled1: true, //质控计划是否可修改
            isDisabled2: true, //检测项中得测定上限 测定下限 方法检出限是否可比编辑
            url: "",
            loading1: true,
            WorkFlowMsg:"",

            enableStatusValue: '',
            searchName: '',
            sampleTypeValue: '',
            typeofAbilityTableDateValue: '',
            abilityDetailShow: false,
            currentPage: 1,
            methodsTableDateValue: '',
            addAnalysisShow: false,
            deleteConfirmShow: false,
            popupShow: false,

            mainEquipTypeValue1: '',
            mainEquipTypeValue2: '',
            selectedjiancefangfa: '',
            isRepeat: true,
            stationName:"厂站",

            methodsType: {},
        }
    },
    props: ['addVisible', 'fuzhiFlag', 'editFlag', 'abilityDetail', 'newOrEdit', 'canEdit', 'itemList', 'equipmentList', 'QcPlanList'],
    components: {
        addyiqi,
        addQcPlan,
        reviewFlow
    },
    computed: {
        ...mapState(['enableStatus', 'objectSelect', 'sampleType', 'bottleOptions', 'groupSelect', 'abilityTableDate', 'yesorno', 'addyiqi', 'unitTableDate', 'ruleSelect', 'dataSelect', 'submitType', 'typeSelect']),

    },
    mounted() {
        this.$store.dispatch('dogetDictionary') //接收vuestore里面数据字典数据
        this.$store.dispatch("getAllBottles");
        for (var i in this.objectSelect.itemList) {
            if (this.objectSelect.itemList[i].name == "水") {
                this.abilityForm.detectObject = this.objectSelect.itemList[i].code
            }

        }

        this.readAllUnit();
        this.readAllItem('');
        this.stationName = this.util.getStationName()

    },
    watch: {
        abilityDetail() {
            console.log(this.abilityDetail)
            for (var i in this.abilityDetail) { //赋值
                this.abilityForm[i] = this.abilityDetail[i];

                var arr = [];

                var defaultAnalysts = {};
                if (i === 'defaultAnalysts') {
                    defaultAnalysts.defaultAnalysts = this.abilityForm[i];
                    arr.push(defaultAnalysts)
                    this.abilityForm[i] = arr;
                }

            }
            this.qcDetecList = this.abilityForm.qcDetecList;

            if (this.abilityForm.createTime != undefined) {
                this.abilityForm.createTime = this.abilityForm.createTime.slice(0, this.abilityForm.createTime.indexOf("."));
            }
            if (this.abilityForm.updateTime != undefined) {
                this.abilityForm.updateTime = this.abilityForm.updateTime.slice(0, this.abilityForm.updateTime.indexOf("."));
            }
            if (this.abilityForm.cmaStatus == undefined) {
                this.abilityForm.cmaStatus = 0;
            }
            if (this.abilityForm.cnasStatus == undefined) {
                this.abilityForm.cnasStatus = 0;
            }
            this.isStatus = this.abilityForm.status
            this.oldVersion = this.abilityForm.version;
            this.detectAbiltyId = this.abilityForm.id;
            this.methodId = this.abilityForm.method
            this.getItem();
            this.getMethodAnalysis();
            this.getMethods();
            this.getMainEquip();
            this.showOpers()
             this.getDeteBottle()

        },
        addVisible(val) {
            if (val) {
                this.activeTab = 'first'
                // 如果是编辑查看或者复制新增时 再这里不调用方法和仪器接口，
                //解决方法和仪器异步（调用接口时this.abilityForm的方法和仪器id没取到值）问题
                if (this.newOrEdit != 'edit' && this.newOrEdit != 'look' && this.newOrEdit != 'copy') {
                    this.getMethods();
                    this.getMainEquip();
                    this.showOpers()

                }
            }
        },
        activeTab(val) {
            if (val == 'second') {
                // this.getMethodAnalysis();
            } else if (val == 'four' || val == 'ten') {
                this.getAblityEquipment()
            } else if (val == 'third') {
                this.getDeteBottle()
            }else if (val == 'five') {
                this.getQcPlan()
            } else if (val == 'six') {
                this.readUser('');
            } else if (val == 'hhh') {
                if (process.env.NODE_ENV == 'development') {
                    this.url = "../../static/workflow.html?id=" + this.abilityForm.id + "&procInstType=" + this.procInstType + "&fromModel=look"

                } else {
                    this.url = "static/workflow.html?id=" + this.abilityForm.id + "&procInstType=" + this.procInstType + "&fromModel=look"

                }
                var that = this;
                window.addEventListener('message', that.handleMessage)

            }
        }

    },
    methods: {
      changeHas(val,status){
        var data = {id:this.abilityForm.id}
        if(status == 'cmaStatus'){
          data.cmaStatus = Number(val);
        }else{
           data.cnasStatus = Number(val);
        }
        this.$http({
            method: 'post',
            apiUrl: '/technology/updateAuthentication',
            params: data,
            isJson: true,
        }).then(res => {
            if (res.code === 0) {
               this.$parent.readAbility(this.$parent.abilityQuery)
            }
           })
      },
      changeItem(val,row,item){

        var arr = []
        var list = [...this.itemBeanList,...this.analysisBeanList]
        list.forEach((item) =>{
          if(item.formula != undefined && item.status == 1){  //取出所有检测项和分析项启用状态 有公式的公式值
            var formula = JSON.parse(JSON.stringify(item.formula))
            formula = formula.replace(/{/g, '');
            formula = formula.replace(/}/g, '');
            formula = formula.replace(/#/g, '');
            arr = [...arr,...formula.split(',')]
          }
        })

        if(item == 'item'){
          var code = row.itemCode
        }else{
          var code = row.code
        }
        if(arr.indexOf(code) !== -1 && val == 0){
          this.$confirm('该项目/分析项关联了公式，是否继续关闭？', '提示', {
            confirmButtonText: '继续',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {

          }).catch(() => {
            row.status = row.status == 0?1:0
            this.$message({
              type: 'info',
              message: '已取消关闭'
            });
          });
        }



      },
        handleMessage(event) {
            const data = event.data
            switch (data.cmd) {
                case 'loadingHide':
                    this.loading1 = false;
                    this.WorkFlowMsg = "";
                    break;
                case 'errorMsg':
						this.loading1 = false;
						this.WorkFlowMsg = "没有查询到审核信息"
					break;
            }
        },
        // 验证保留位数只能为整数
        decNumber(row) {
            var reg = /^([0-9]?|10)$/;
            var isInt = reg.test(Number(row.decimalNumber));
            if (!isInt) {
            row.decimalNumber = null;
            }
        },
        showOpers() {
            // 检测方法和主仪器类别和使用校准曲线 输入框编辑状态和提交按钮出现一致，所以用isSubmit
            if (this.newOrEdit == 'new' || this.newOrEdit == 'copy') { //新增进入
                this.isSave = true;
                this.isSubmit = true;
                this.isNewViserion = false; //新版本按钮
                this.isDisabled = true;
                this.isDisabled1 = true;
                this.isDisabled2 = true;
            }
            if (this.newOrEdit == 'newVersion') {
                this.isSave = false;
                this.isSubmit = true;
                this.isNewViserion = false; //新版本按钮
                this.isDisabled = false;
                this.isDisabled1 = true;
                this.isDisabled2 = true;

            }
            if (this.newOrEdit == 'edit') { //编辑进入
                // 启用状态下 管理员进入
                if (this.$parent.userOpernation.openUpdate.display && this.isStatus == 1) {
                    this.isSave = false;
                    this.isSubmit = false;
                    this.isNewViserion = true; //新版本按钮
                    this.isDisabled = false;
                    this.isDisabled1 = true;
                    this.isDisabled2 = true;

                }
                // 启用状态下 普通用户进入
                if (!this.$parent.userOpernation.openUpdate.display && this.isStatus == 1) { //启用状态的编辑
                    this.isSave = false;
                    this.isSubmit = false;
                    this.isNewViserion = true; //新版本按钮
                    this.isDisabled = false;
                    this.isDisabled1 = true;
                    this.isDisabled2 = false;
                }
                if (this.abilityForm.source != undefined && this.abilityForm.source != null && this.abilityForm.source != '') { //如果是从中心库生成的  不可生成新版本
                    this.isNewViserion = false; //新版本按钮出现
                    this.isDisabled1 = false;
                }

                if (this.isStatus == 2) { //草稿状态的编辑
                    this.isSave = true;
                    this.isSubmit = true;
                    this.isNewViserion = false; //新版本按钮
                    this.isDisabled = true;
                    this.isDisabled1 = true;
                    this.isDisabled2 = true;
                }
                if (this.isStatus == 4) { //草稿状态的编辑
                    this.isSave = false;
                    this.isSubmit = true;
                    this.isNewViserion = false; //新版本按钮
                    this.isDisabled = true;
                    this.isDisabled1 = true;
                    this.isDisabled2 = true;
                }
            }
            if (this.newOrEdit == 'look' || this.newOrEdit == 'review') { //详情
                this.isSave = false;
                this.isSubmit = false;
                this.isNewViserion = false; //新版本按钮
                this.isDisabled = false;
                this.isDisabled1 = false;
                this.isDisabled2 = false;

            }

        },
        //
        changeLine(val) {
            // if (this.outMethod.length == 0) {
            //     this.$notify({
            //         type: "warning",
            //         message: "请先选择检测方法!",
            //         title: "警告"
            //     })
            //     this.abilityForm.doUseCurve = '';
            // } else {
            //     if (val) {
            //         var flag = false;
            //         for (var i in this.analysisBeanList) {
            //             if (this.analysisBeanList[i].type == 1) {
            //                 flag = true;
            //             }
            //         }
            //         if (!flag) {
            //             this.$notify({
            //                 type: "warning",
            //                 message: "无信号分析项，不能使用校准曲线!",
            //                 title: "警告"
            //             })
            //             this.abilityForm.doUseCurve = '';
            //         }
            //     }
            // }
        },
        // 审核流弹框
        reviewFlowPop() {
            this.reviewFlowShow = true;
            this.reviewData = this.abilityForm;
        },
        // 关闭弹框，刷新页面
        readAbility() {
            this.$store.dispatch('getWorkflowList', 0).then(res => {
                this.$notify({
                    showClose: true,
                    message: '操作成功',
                    type: 'success',
                    title:"成功"
                })
            })
            this.close('abilityForm');
            this.$parent.readAbility(this.$parent.abilityQuery)

        },
        getDeteBottle(){
            var data = {
                id:this.abilityForm.id
            }
             this.abilityForm.bottle = [];
            this.$http({
                method: 'post',
                apiUrl: '/technology/getDeteBottle.htm',
                params: data,
                isJson: false,
            }).then(res => {
                if (res.code === 0) {
                    if(res.data !== undefined){
                        this.abilityForm.bottle.push(res.data);
                    }else{
                        this.abilityForm.bottle.push({
                            doAlone: false,
                            capacity: 100,
                            bottleType: "",
                            media:null,
                            saveTime:null,
                        })
                    }
                    console.log(this.abilityForm.bottle)

                }

            })
        },
        // 能力参数启用状态下编辑采样要求
        updateDetectabilityBean(newEdit) {
            var data = this.abilityForm.bottle[0]
            data.fRef =  this.detectAbiltyId
            if( this.abilityForm.bottle[0].id != undefined){
                data.id = this.abilityForm.bottle[0].id;
            }
            if(newEdit == 'new' || newEdit == 'newVersion' || newEdit == 'copy'){
                data.id = '';
            }
            if( newEdit != 'clickSave'){
                if(data.bottleType != null && data.bottleType != ''){
                    this.addBottle(data)
                }
            }else{
                this.addBottle(data,newEdit)
            }

        },
        addBottle(data,newEdit){
            this.$http({
                method: 'post',
                apiUrl: '/technology/addDeteBottle.htm',
                params: data,
                isJson: true,
            }).then(res => {
                if (res.code === 0) {
                    if(newEdit == 'clickSave'){
                        this.$notify({
                            title: "成功",
                            message: "修改容器成功！",
                            type: "success"
                        })
                    }

                }

            })
        },
        // 根据方法id获取分析项
        getMethodAnalysis() {
            var data = {
                id: this.methodId
            }
            this.$http({
                method: 'post',
                apiUrl: '/technology/queryAnalysisList.htm',
                params: data,
                isJson: false,
            }).then(res => {
                if (res.code === 0) {
                    for (var i in res.data) { //把别名的 { }和，过滤掉
                        if (res.data[i].formulaAlias != undefined) {
                            var value = res.data[i].formulaAlias.replace(/{/g, '');
                            value = value.replace(/}/g, '');
                            value = value.replace(/,/g, '');
                            res.data[i].formulaAlias = value;
                        }
                    }
                    this.analysisBeanList = res.data;
                }

            })
        },
        // 根据能力参数id获取主辅仪器列表
        getAblityEquipment() {
            this.$http({
                method: 'post',
                apiUrl: '/technology/readEquipmentBeanList.htm',
                params: {
                    id: this.detectAbiltyId
                },
                isJson: false,
            }).then(res => {
                if (res.code === 0) {
                   this.mainEquipmentBeanList = [];
                    this.equipmentBeanList = []
                    if (res.data.length != 0) {
                        for(var i in res.data){
                            if(res.data[i].isMain){
                                this.mainEquipmentBeanList.push(res.data[i])
                            }else{
                                this.equipmentBeanList.push(res.data[i])
                            }
                        }
                    }
                    this.reLoad();
                }
            })
        },
        // 设置默认仪器
        changeisDefault(row,val){
            row.fRef = this.detectAbiltyId;
             this.$http({
                method: 'post',
                apiUrl: '/technology/setDefaultEquip.htm',
                params:row,
                isJson: true,
            }).then(res => {
                if (res.code === 0) {
                   this.$notify({
                        title:"成功",
                        message:"设置成功!",
                        type:"success",
                   });
                   this.getAblityEquipment()
                }
            })

        },
        // 删除主辅仪器
        deleteEquip(row){
            this.$confirm('是否删除', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var that = this;
                var param = {
                 id: row.id,
                }
                this.$http({
                    apiUrl: '/technology/deleteEquip.htm',
                    type: 'post',
                    params: param,
                    }).then(res => {
                        if (res.code === 0) {
                            this.$message({
                            type: 'success',
                            message: '删除成功!'
                            });
                            this.getAblityEquipment()
                        }
                    });
            }).catch(() => {
                this.$message({
                type: 'info',
                message: '已取消删除'
                });
            });
        },
        // 根据能力参数id获取质控计划列表
        getQcPlan() {
            this.$http({
                method: 'post',
                apiUrl: '/technology/readQcPlanBeanList.htm',
                params: {
                    id: this.detectAbiltyId
                },
                isJson: false,
            }).then(res => {
                if (res.code === 0) {
                    this.qcDetecList = res.data;
                }
            })
        },
        // 删除质控计划
        deleteQcPlan(row){
            this.$confirm('是否删除', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var that = this;
                var param = {
                 id: row.id,
                }
                this.$http({
                    apiUrl: '/technology/deleteQcDetec.htm',
                    type: 'post',
                    params: param,
                    }).then(res => {
                        if (res.code === 0) {
                            this.$message({
                            type: 'success',
                            message: '删除成功!'
                            });
                            this.getQcPlan()
                        }
                    });
            }).catch(() => {
                this.$message({
                type: 'info',
                message: '已取消删除'
                });
            });
        },
        //  根据能力参数id获取检测项目
        getItem() {
            this.$http({
                method: 'post',
                apiUrl: '/technology/readDetecItemList.htm',
                params: {
                    id: this.detectAbiltyId
                },
                isJson: false,
            }).then(res => {
                if (res.code === 0) {
                  // var arr = []
                    for (var i in res.data) { //把别名的 { }和，过滤掉
                        if (res.data[i].formulaAlias != undefined) {
                            var value = res.data[i].formulaAlias.replace(/{/g, '');
                            value = value.replace(/}/g, '');
                            value = value.replace(/,/g, '');
                            res.data[i].formulaAlias = value;

                            // var formula = JSON.parse(JSON.stringify(res.data[i].formula))
                            // formula = formula.replace(/{/g, '');
                            // formula = formula.replace(/}/g, '');
                            // arr = [...arr,...formula.split(',')]
                        }
                    }
                    this.itemBeanList = res.data;

                }
            })

        },
        // 搜索检测人
        readUser(item, type) {
            this.$http({
                method: 'post',
                apiUrl: '/resource/getEmployByDictionaryId.htm',
                params: {
                    name: item,
                    detectability: this.detectAbiltyId
                },
                isJson: false,
            }).then(res => {
                if (res.code === 0) {
                    if (type == 1) {
                        if (res.data.length == 0) {
                            this.$notify({
                                title: '警告',
                                message: '请先到到人员检测能力维护',
                                type: 'warning'
                            })
                        }
                    }
                    this.userData = res.data;

                }

            })
        },
        // 添加编辑弹框 搜索检测项目
        readAllItem(item) {
            this.allItem = [];
            this.$http({
                method: 'post',
                apiUrl: '/technology/readAllItem.htm',
                params: {
                    name: item
                },
                isJson: true
            }).then(res => {
                if (res.code == 0) {
                    this.allItem = res.data;
                }

            })
        },
        readAllUnit(item) {
            this.allUnit = [];
            this.$http({
                method: 'post',
                apiUrl: '/technology/readLabUnitList.htm',
                params: {
                    ename: item
                },
                isJson: true
            }).then(res => {
                if (res.code == 0) {
                    this.allUnit = res.data;
                }

            })
        },

        getTreeDeepArr(key, treeData) {
            let arr = []; // 在递归时操作的数组
            let returnArr = []; // 存放结果的数组
            let depth = 0; // 定义全局层级
            // 定义递归函数
            function childrenEach(childrenData, depthN) {
                for (var j = 0; j < childrenData.length; j++) {
                    depth = depthN; // 将执行的层级赋值 到 全局层级
                    arr[depthN] = (childrenData[j].value);
                    if (childrenData[j].value == key) {
                        // returnArr = arr; // 原写法不行, 因 此赋值存在指针关系
                        returnArr = arr.slice(0, depthN + 1); //将目前匹配的数组，截断并保存到结果数组，
                        break
                    } else {
                        if (childrenData[j].children) {
                            depth++;
                            childrenEach(childrenData[j].children, depth);
                        }
                    }
                }
                return returnArr;
            }
            return childrenEach(treeData, depth);
        },
        // 检测方法
        getMethods() {
            this.$http({
                method: 'post',
                apiUrl: '/technology/readMethodAndType.htm',
            }).then(res => {
                if (res.code === 0) {
                    this.MethodAndType = this.deepClone(res.data)
                    this.outMethod = this.getTreeDeepArr(this.abilityForm.method, this.MethodAndType)
                    if (this.outMethod.length != 0) {
                        var firstName = null;
                        var secondName = null;
                        for (var i in this.MethodAndType) {
                            if (this.outMethod[0] == this.MethodAndType[i].value) {
                                firstName = this.MethodAndType[i].label
                            }
                            for (var j in this.MethodAndType[i].children) {
                                if (this.outMethod[1] == this.MethodAndType[i].children[j].value) {
                                    secondName = this.MethodAndType[i].children[j].label;
                                }
                            }
                        }
                        this.outMethodName = firstName + " / " + secondName
                    }
                }

            })
        },
        // 处理检测方法数据，id，code转换成value
        deepClone(obj) {
            var result, oClass = this.isClass(obj);
            //确定result的类型
            if (oClass === "Object") {
                result = {};
            } else if (oClass === "Array") {
                result = [];
            } else {
                return obj;
            }
            for (let key in obj) {
                var copy = obj[key];

                if (this.isClass(copy) === "Object") {
                    result[key] = this.deepClone(copy); //递归调用
                } else if (this.isClass(copy) === "Array") {

                    if (obj['children'].length !== 0) {
                        result[key] = this.deepClone(copy); //递归调用
                    }
                } else {
                    if (key === 'name') {
                        result['label'] = obj[key];
                    }
                    if (key === 'id') {
                        result['value'] = obj[key];
                    }
                    if (key === 'code') {
                        result['code'] = obj[key];
                    }
                    if (key === 'disabled') {
                        result['disabled'] = obj[key];
                    }
                    // if( key === 'id') {
                    //   result['id']=obj[key];
                    // }
                    if (key === 'children' && obj[key].length !== 0) {
                        result['children'] = obj[key];
                    }
                }
            }
            return result;

        },
        //返回传递给他的任意对象的类
        isClass(o) {
            if (o === null) return "Null";
            if (o === undefined) return "Undefined";
            return Object.prototype.toString.call(o).slice(8, -1);
        },

        reLoad() {
            this.reload = false;
            this.$nextTick(() => {
                //dom元素更新后执行，此时能拿到p元素的属性
                // this.message = this.$refs.myWidth.offsetWidth;

                this.reload = true;
            })
        },
        //获取主仪器
        getMainEquip() {
            this.$http({
                method: 'post',
                apiUrl: '/technology/readMainEquipTypeList.htm',
            }).then(res => {
                if (res.code === 0) {
                    this.mainEquipmentType = this.deepClone(res.data);
                    this.outMainEquipment = this.getTreeDeepArr(this.abilityForm.mainEquiptype, this.mainEquipmentType)

                    if (this.outMainEquipment.length != 0) {
						var firstName = null;
                    	var secondName = null;
                        for (var i in this.mainEquipmentType) {
                            if (this.outMainEquipment[0] == this.mainEquipmentType[i].value) {
                                firstName = this.mainEquipmentType[i].label
                            }
                            for (var j in this.mainEquipmentType[i].children) {
                                if (this.outMainEquipment[1] == this.mainEquipmentType[i].children[j].value) {
                                    secondName = this.mainEquipmentType[i].children[j].label;
                                }
                            }
                        }
                        this.outMainEquipmentName = firstName + " / " + secondName
                    }

                }

            })
        },
        // 根据选中的值取对应的code 一起提交
        getCascaderCode(value, arr) {
            for (var i in arr) {
                for (var j in arr[i].children) {
                    if (value == arr[i].children[j].value) {
                        return arr[i].children[j].code
                    }
                }
            }
        },
        changeStatus() { //生成新版本  改变newOrEdit和canEdit的状态
            this.$confirm('是否生成新版本', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$emit('update:addVisible', false)
                this.$nextTick(() => {
                    this.$emit('update:canEdit', true)
                    this.$emit('update:newOrEdit', 'newVersion')
                    this.$emit('update:addVisible', true)
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消生成新版本'
                });
            });
        },
        // 提交
        submitAbility(value) {
            this.detectAbiltyId = '';
            this.$refs.abilityForm.validate((valid) => { //表单验证
                if (valid) {
                    // 提交时验证检测方法和主仪器类别是否为空
                    var flag = true
                    if (this.outMethod.length == 0) {
                        $('.methodsVail.method').addClass('is-error')
                        this.methodError = true;
                        flag = false
                    }
                    // if (this.outMainEquipment.length == 0) {
                    //     $('.methodsVail.equipVail').addClass('is-error')
                    //     this.equipError = true;
                    //     flag = false
                    // }
                    if (flag) {
                        for (var i in this.userData) {
                            if (this.abilityForm.defaultAnalysts[0].defaultAnalysts == this.userData[i].account) {
                                this.defaultAnalystsName = this.userData[i].name
                            }
                        }
                        var data = {
                            name: this.abilityForm.name,
                            detectObject: this.abilityForm.detectObject,
                            detectabilityType: this.abilityForm.detectabilityType,
                            method: this.outMethod[this.outMethod.length - 1], //取数组的最后一个id
                            mainEquiptype: 0,
                            doUseCurve: this.abilityForm.doUseCurve,
                            // bottleType: this.abilityForm.bottle[0].bottleType,
                            // capacity: this.abilityForm.bottle[0].capacity,
                            // doAlone: this.abilityForm.bottle[0].doAlone,
                            group: this.abilityForm.group,
                            methodCode: this.getCascaderCode(this.outMethod[this.outMethod.length - 1], this.MethodAndType),
                            mainEquiptypeCode: 0,
                            defaultAnalysts: this.abilityForm.defaultAnalysts[0].defaultAnalysts,
                            defaultAnalystsName: this.defaultAnalystsName,
                            qcDetecList: this.qcDetecList
                        };
                        if (this.newOrEdit == 'new' || this.newOrEdit == 'copy') {
                            var url = '/technology/addDetectability.htm';
                            if (value == 'commit') {
                                data.submitType = this.submitType.submitOpen;
                            } else if (value == 'save') {
                                data.submitType = this.submitType.submitDraft;
                            }
                        } else if (this.newOrEdit == "newVersion") {
                            var url = "/technology/addDetectability.htm";
                            data.id = this.abilityForm.id;
                            data.parentVersion = this.abilityForm.parentVersion;
                            if (value == 'commit') {
                                data.submitType = this.submitType.submitOpen;
                            } else if (value == 'save') {
                                data.submitType = this.submitType.submitDraft;
                            }
                        } else {
                            var url = '/technology/updateDetectability.htm';
                            data.id = this.abilityForm.id;
                            if (value == 'commit') {
                                data.submitType = this.submitType.submitOpen;
                            } else if (value == 'save') {
                                data.submitType = this.submitType.submitDraft;
                            }
                        }
                        this.isRepeat = false;
                        this.$http({
                            method: 'post',
                            apiUrl: url,
                            params: data,
                            isJson: true,
                            isLoading:true
                        }).then(res => {
                            this.isRepeat = true;
                            if (res.code == 0) {

                                // if (this.newOrEdit == 'edit') {
                                //     this.detectAbiltyId = this.abilityForm.id
                                // } else {
                                //     this.detectAbiltyId = res.data
                                // }
                                this.detectAbiltyId = res.data
                                this.submitItem();
                                this.submitAnalysis('save');
                                this.updateDetectabilityBean(this.newOrEdit);
                                this.close('abilityForm');

                                this.$parent.readAbility(this.$parent.abilityQuery)
                            }

                        }).catch(() => {

                        });
                    }
                } else {
                    if (this.outMethod.length == 0) {
                        $('.methodsVail.method').addClass('is-error')
                        this.methodError = true;
                    }

                    // if (this.outMainEquipment.length == 0) {
                    //     $('.methodsVail.equipVail').addClass('is-error')
                    //     this.equipError = true;
                    // }
                    // return false;
                }
            });
        },
        close(formName) {

            this.$refs[formName].resetFields();
            this.$emit('update:addVisible', false);
            this.isRepeat = true;
            this.abilityForm = {
                name: '',
                detectObject: '',
                doUseCurve: true,
                mainEquiptype: '',
                status: 2,
                method: '',
                methodBean: {
                    analysisBeanList: [],
                    itemBeanList: [],
                },
                bottle: [{}], //容器
                defaultAnalysts: [{}], //默认检测人列表
                version: '',
                cnasStatus:0,
                cmaStatus:0,

                // doDefaultMethod: null,
            };
            this.outMainEquipment = [];
            this.outMainEquipmentName = [];
            this.outMethod = [];
            this.outMethodName = null;
            this.itemBeanList = [];
            this.analysisBeanList = [];
            this.qcDetecList = [];
            this.activeTab = 'first';
            this.isSave = false; //保存按钮显示和隐藏,新增和生成新版本，状态为草稿时出现
            this.isSubmit = true; //提交按钮 只有查看时不出现
            this.isDisabled = true; //编辑状态
            this.isNewViserion = false; //新版本按钮
            this.isDisabled1 = true; //编辑状态
            this.isDisabled2 = true;
            this.loading1 = true;
            this.WorkFlowMsg = "";

        },
        // 级联选择器选中时调用检测项目与分析项列表接口
        changeMethod(value) {
            this.abilityForm.doUseCurve = true;
            $('.methodsVail.method').addClass('is-success').removeClass('is-error')
            this.methodError = false;
            this.methodId = null;
            this.methodId = value[value.length - 1]
            console.log(this.methodId)
            if (value.length > 1) {
                var data = {
                    id: value[value.length - 1]
                }
                this.$http({
                    method: 'post',
                    apiUrl: '/technology/readMethodById.htm',
                    params: data,
                    isJson: false,
                }).then(res => {
                    if (res.code === 0) {
                        for (var i in res.data.itemBeanList) { //把别名的 { }和，过滤掉
                            res.data.itemBeanList[i].id = null;
                            this.$set(res.data.itemBeanList[i], 'status', 1) //默认status为1 启用状态

                            if (res.data.itemBeanList[i].formulaAlias != undefined) {
                                var value = res.data.itemBeanList[i].formulaAlias.replace(/{/g, '');
                                value = value.replace(/}/g, '');
                                value = value.replace(/,/g, '');
                                res.data.itemBeanList[i].formulaAlias = value;
                            }
                        }
                        for (var i in res.data.analysisBeanList) { //把别名的 { }和，过滤掉
                            if (res.data.analysisBeanList[i].formulaAlias != undefined) {
                                var value = res.data.analysisBeanList[i].formulaAlias.replace(/{/g, '');
                                value = value.replace(/}/g, '');
                                value = value.replace(/,/g, '');
                                res.data.analysisBeanList[i].formulaAlias = value;
                            }
                        }
                        this.itemBeanList = res.data.itemBeanList;
                        this.analysisBeanList = res.data.analysisBeanList;
                        this.abilityForm.group = res.data.group;

                    }

                })
            }

        },
        // 选中仪器
        changeEquipMent(val) {
            $('.methodsVail.equipVail').addClass('is-success').removeClass('is-error')
            this.equipError = false;
        },
        // 添加或者修改主辅仪器
        addyiqiShow(newOrEdit) {
            this.addyiqishow = true;
            this.newOrEditEquip = newOrEdit
        },
        //添加或者修改质控计划
        addQcPlanShow() {
            this.addQcshow = true;
        },
        delQcPlan(index) {
            this.qcDetecList.splice(index, 1)
        },
        // 修改质控计划是否必做
        changeIsDo(val, row) {
            var data = {
                id: row.id,
                isDo: val,
            }
            this.$http({
                method: 'post',
                apiUrl: '/technology/updateQcDetec.htm',
                params: data,
                isJson: false,
            }).then(res => {
                if (res.code === 0) {
                    this.$message({
                        type: 'success',
                        message: '修改质控计划成功!',
                    })
                    this.getQcPlan()
                }

            })

        },
        addAnalysis() {
            this.addAnalysisShow = true;
        },
        // 保存检测方法的分析项
        submitAnalysis(isSave) {
            // for(var i in this.analysisBeanList){
            //   this.$set(this.analysisBeanList[i],'unit',this.analysisBeanList[i].unitName)
            //   // this.itemBeanList[i].unit = this.itemBeanList[i].unitName
            // }
            if(this.analysisBeanList.length != 0){
                this.$http({
                    method: 'post',
                    apiUrl: '/technology/updateAnalysis.htm',
                    params: this.analysisBeanList,
                    isJson: true,
                }).then(res => {
                    if (res.code === 0) {
                        if(isSave != 'save'){
                            this.$notify({
                                type: 'success',
                                message: '操作成功!',
                                title:"成功"
                            });
                        }

                    }

                })
            }


        },
        // 保存检测项目
        submitItem() {
            for (var i in this.itemBeanList) {
                this.itemBeanList[i].fRef = this.detectAbiltyId;
                this.itemBeanList[i].doDefaultMethod = false;
                this.itemBeanList[i].method = this.methodId;
            }
            var data = {
                id: this.detectAbiltyId,
                itemBeanList: this.itemBeanList
            }
            this.$http({
                method: 'post',
                apiUrl: '/technology/updateDetecItem.htm',
                params: data,
                // apiUrl: '/technology/updateDetectabilityItem.htm',
                // params: this.itemBeanList,
                isJson: true,
            }).then(res => {
                if (res.code === 0) {
                    this.$notify({
                        type: 'success',
                        message: '操作成功!',
                        title:"成功"
                    });
                    this.getItem()
                }

            })

        },
        validAnalysts() {
            this.readUser('', 1);
        },
        addAnalysts(a) {
            console.log(a, this.abilityForm)
            var data = {};
            data.id = this.abilityForm.id;
            for (var i in this.userData) {
                if (a == this.userData[i].account) { // 检测人
                    data.defaultAnalysts = this.userData[i].account;
                    data.defaultAnalystsName = this.userData[i].name;
                }
            }
            this.$http({
                method: 'post',
                apiUrl: '/technology/addDefaultAnalysts.htm',
                params: data,
                isJson: true,
            }).then(res => {
                if (res.code === 0) {
                    this.$message({
                        type: 'success',
                        message: '修改默认检测人成功!',
                    });
                }

            })

        },
        addLittleAnalysis() {
            this.analysisItemTableDate.push({
                analysisItemID: '24567823645001',
                analysisItemName: '',
                isIndex: '0',
                unit: '',
                analysisItemTypeID: '',
                analysisItemTypeName: '',
                roundingTypeID: '',
                roundingTypeName: '',
                retainDdigit: '',
                analysisItemStatus: '',
                canedit: true
            })
        },
        addBigAnalysis() {
            this.jiancexiangmuTableDate.push({
                analysisItemName: '',
                isIndex: '1',
                unit: '',
                analysisItemTypeID: '',
                analysisItemTypeName: '',
                roundingTypeID: '',
                roundingTypeName: '',
                retainDdigit: '',
                analysisItemStatus: '',
                canedit: true
            })
        }
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>
.el-form .el-form-item {
    display: inline-block;
    width: 24.5%;
}

.el-col-22 .el-select {
    width: 100%;
}

.el-form.demo-form-inline {
    padding-top: 15px
}

.abilityForm .el-form-item {
    margin-bottom: 10px !important;
}

.form {
    height: 125px;
}

.elTab {
    height: calc(100% - 125px);
    padding: 0 20px;
}

.elTab .el-tabs {
    height: 100%;
}
</style><style>
.abilityAddcon .elTab .el-tabs .el-tabs__content {
    height: calc(100% - 55px)
}

.abilityAddcon .elTab .el-tabs .el-tab-pane {
    height: 100%;
}

.abilityAddcon .user-footer {
    height: 35px;
    line-height: 35px;
}

.methodsVail .el-form-item__label:before {
    content: '*';
    color: #f56c6c;
    margin-right: 4px;
}
</style>
